import { _decorator } from 'cc';
import { GameCore } from '../../Base/Class';
import { setClassName } from '../../Base/Global';

export class UIComponentProxyManager extends GameCore.ClassBase
{
    private componentProxyCacheMap = new Map<number, any>();
    public RegisterComponentProxy(proxy: GameCore.ClassBase) 
    {
       var instanceId = proxy.instanceId;
       if(this.componentProxyCacheMap.has(instanceId))
       {
         console.error("register repeate! " + proxy.className);
         return;
       }
       this.componentProxyCacheMap.set(instanceId, proxy);
    }

    public GetComponentProxy<T extends GameCore.ClassBase>(instanceId : number) : T
    {
       if(this.componentProxyCacheMap.has(instanceId))
       {
            return this.componentProxyCacheMap.get(instanceId) as T;
       }
       return null;
    }

    public UnRegisterComponentProxy(proxy: GameCore.ClassBase)
    {
        var instanceId = proxy.instanceId;
        this.componentProxyCacheMap.delete(instanceId)
    }
}
setClassName(UIComponentProxyManager, "UIComponentProxyManager")